<?php

namespace MLM\Model;

use MLM\Model\Generic\Object\Map;
use MLM\Model\Generic\Object\Mapper;

class Sn extends Mapper {

    protected $_storage;
    
    //put your code here
    public function __construct($data = array(), $map = array()) {
        parent::__construct($data, $map);
    }
    
    public function getRandom($len) {

        $start = 1;
        $start .= str_repeat(0, $len-1);

        $end = str_repeat(9, $len);

        do {
            $agt_no = mt_rand($start, $end);
            $valid = true;
            if (preg_match('/(\d)\1\1/', $agt_no))
                $valid = false; // Same digit three times consecutively
            elseif (preg_match('/(\d).*?\1.*?\1.*?\1/', $agt_no))
                $valid = false; // Same digit four times in string
        } while ($valid === false);
        return $agt_no;
    }

    public function generatePIN($len) {
        $start = 1;
        $start .= str_repeat(0, $len-1);

        $end = str_repeat(9, $len);

        do {
          $pin_no = mt_rand($start,$end);
          $valid = true;
          if (preg_match('/(\d)\1\1/', $pin_no))
            $valid = false; // Same digit three times consecutively
          elseif (preg_match('/(\d).*?\1.*?\1.*?\1/', $pin_no))
            $valid = false; // Same digit four times in string
        } while ($valid === false);
        return $pin_no;
    }

    
}
